<?php defined("MAIN_DIR") or die("No direct access");

$bank_path = explode(".",$route->getPath(3));
if (count($bank_path) < 2 || $bank_path[0] == "" || $bank_path[1] != "html") {
	to("/$c_name/banks/");
} else {
	$bank_path = $bank_path[0];
}

$bank_res = mysql_query("select * from `bank` where `link` = '$bank_path' and `city_id` = '$_SESSION[city]' limit 1");
if (mysql_num_rows($bank_res) == 0) {
	to("/$c_name/banks/");
}

$bank_row = mysql_fetch_array($bank_res);
$city_row = mysql_fetch_array(mysql_query("select * from `city` where `city_id` = '$bank_row[city_id]' limit 1"));


$head_title = $bank_row['name']." в ".$city_row['city_name_pred'];
$head_description = "Контактная информация банка «".$bank_row['name']."» в ".$city_row['city_name_pred'].". Информация по вкладам и кредитам банка.";
$head_keywords = $bank_row['name']." ".$city_row['city_name']." вклады кредиты ипотека кредитные карты";

require_once APP.HEADFILE;
?>
<script type="text/javascript" src="/files/js/bank_list.js"></script>
<h1><?php echo $bank_row['name']." в ".$city_row['city_name_pred']?></h1>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
	<tr>
		<td width="344" align="left" valign="top">
			<?php if ($bank_row['full_name'] != "") {
				?><div class="bank_info_heading_top">Название</div>
				<div class="bank_info_text"><?php echo $bank_row['full_name']; ?></div><?php
			}
			if ($bank_row['license'] != '') {
				?><div class="bank_info_heading">Регистрационный номер</div>
				<div class="bank_info_text"><?php echo $bank_row['license']; ?></div><?php
			}
			if ($bank_row['address'] != "") {
				?><div class="bank_info_heading">Адрес в <?php echo $city_row['city_name_pred']?></div>
				<div class="bank_info_text"><?php echo $bank_row['address']; ?></div><?php
			}
			if ($bank_row['phone'] != "") {
				?><div class="bank_info_heading">Телефон(ы)</div>
				<div class="bank_info_text"><?php echo $bank_row['phone']; ?></div><?php
			}
			if ($bank_row['site'] != "") {
				?><div class="bank_info_heading">Интернет-сайт</div>
				<div class="bank_info_text"><?php echo $bank_row['site']; ?></div><?php
			}
			if ($bank_row['about'] != "") {
				?><div class="bank_info_heading">О банке</div>
				<div class="bank_info_text"><?php echo $bank_row['about']; ?></div><?php
			}
			?>
		</td>
		<td width="646" align="left" valign="top" id="bank_table">
			<div><h3>Потребительские кредиты</h3></div><?php
			$user_credits_res = mysql_query("select `credit_id`,`name` from `credit` where `bank_id` = '$bank_row[bank_id]' or (`bank_id` = '$bank_row[parent]' and `regionally` = '1')");
			
			if (mysql_num_rows($user_credits_res) > 0)
			{
				?><table width="100%" border="0" cellspacing="0" cellpadding="0">
					<tr>
						<td width="44%" align="left" valign="top" class="bank_info_table_heading"><strong>Название программы</strong></td>
						<td width="15%" align="left" valign="top" class="bank_info_table_heading"><strong>Валюта</strong></td>
						<td width="15%" align="left" valign="top" class="bank_info_table_heading"><strong>Сумма</strong></td>
						<td width="15%" align="left" valign="top" class="bank_info_table_heading"><strong>Срок</strong></td>
						<td width="11%" align="left" valign="top" class="bank_info_table_heading"><strong>Ставка</strong>, %</td>
					</tr><?php
					while ($user_credits_row = mysql_fetch_array($user_credits_res))
					{
						$cc_res = mysql_query("select * from `credit_currency` where `credit_id` = '$user_credits_row[credit_id]' and `type` = '1'");
						$cc_count = mysql_num_rows($cc_res);
						?><tr>
							<td align="left" valign="top" class="bank_info_table" rowspan="<?php
							echo $cc_count;
							?>"><a href="<?php echo "/$c_name";?>/credits/credit/<?php echo $user_credits_row['credit_id'];?>"><?php
								echo $user_credits_row['name'];
							?></a></td><?php
							$i = 0;
							while ($cc_row = mysql_fetch_array($cc_res))
							{
								if ($i > 0)
									echo "<tr>";
								?><td align="left" valign="top" class="bank_table_curency"><?php echo $cc_row['currency']; ?></td>
								<td align="left" valign="top" class="bank_info_table"><?php
									echo "от ".getValue($cc_row['sum_low'])."<br />до ".getValue($cc_row['sum_high']);
								?></td>
								<td align="left" valign="top" class="bank_info_table"><?php
								echo getPeriod($cc_row['period_low'],false)." - ".getPeriod($cc_row['period_high']); ?></td>
								<td align="left" valign="top" class="bank_info_table"><?php
								echo $cc_row['rate_low']."-".$cc_row['rate_high']; ?></td><?php
								$i++;
								if ($i < $cc_count-1)
									echo "</tr>";
							}
						?></tr><?php
					}
				?></table><?php
			}
			else
				echo "<h4 class='gag'>У банка нет потребительских кредитов</h4>";
			?><div><h3>Автокредиты</h3></div><?php
			$auto_res = mysql_query("select `auto_id`,`name` from `auto` where `bank_id` = '$bank_row[bank_id]' or (`bank_id` = '$bank_row[parent]' and `regionally` = '1')");
			if (mysql_num_rows($auto_res) > 0)
			{
				?><table width="100%" border="0" cellspacing="0" cellpadding="0">
					<tr>
						<td width="44%" align="left" valign="top" class="bank_info_table_heading"><strong>Название программы</strong></td>
						<td width="15%" align="left" valign="top" class="bank_info_table_heading"><strong>Валюта</strong></td>
						<td width="15%" align="left" valign="top" class="bank_info_table_heading"><strong>Сумма</strong></td>
						<td width="15%" align="left" valign="top" class="bank_info_table_heading"><strong>Срок</strong></td>
						<td width="11%" align="left" valign="top" class="bank_info_table_heading"><strong>Ставка</strong>, %</td>
					</tr><?php
					while ($auto_row = mysql_fetch_array($auto_res))
					{
						$cc_res = mysql_query("select * from `credit_currency` where `credit_id` = '$auto_row[auto_id]' and `type` = '2'");
						$cc_count = mysql_num_rows($cc_res);
						?><tr>
							<td align="left" valign="top" class="bank_info_table" rowspan="<?php
							echo $cc_count;
							?>"><a href="<?php echo "/$c_name";?>/credits/auto/<?php echo $auto_row['auto_id'];?>"><?php
								echo $auto_row['name'];
							?></a></td><?php
							$i = 0;
							while ($cc_row = mysql_fetch_array($cc_res))
							{
								if ($i > 0)
									echo "<tr>";
								?><td align="left" valign="top" class="bank_table_curency"><?php echo $cc_row['currency']; ?></td>
								<td align="left" valign="top" class="bank_info_table"><?php
									echo "от ".getValue($cc_row['sum_low'])."<br />до ".getValue($cc_row['sum_high']);
								?></td>
								<td align="left" valign="top" class="bank_info_table"><?php
								echo getPeriod($cc_row['period_low'],false)." - ".getPeriod($cc_row['period_high']); ?></td>
								<td align="left" valign="top" class="bank_info_table"><?php
								echo $cc_row['rate_low']."-".$cc_row['rate_high']; ?></td><?php
								$i++;
								if ($i < $cc_count-1)
									echo "</tr>";
							}
						?></tr><?php
					}
				?></table><?php
			}
			else
				echo "<h4 class='gag'>У банка нет автокредитов</h4>";
			?><div><h3>Ипотека</h3></div><?php
			$home_res = mysql_query("select `home_id`,`name` from `home` where `bank_id` = '$bank_row[bank_id]' or (`bank_id` = '$bank_row[parent]' and `regionally` = '1')");
			if (mysql_num_rows($home_res) > 0)
			{
				?><table width="100%" border="0" cellspacing="0" cellpadding="0">
					<tr>
						<td width="44%" align="left" valign="top" class="bank_info_table_heading"><strong>Название программы</strong></td>
						<td width="15%" align="left" valign="top" class="bank_info_table_heading"><strong>Валюта</strong></td>
						<td width="15%" align="left" valign="top" class="bank_info_table_heading"><strong>Сумма</strong></td>
						<td width="15%" align="left" valign="top" class="bank_info_table_heading"><strong>Срок</strong></td>
						<td width="11%" align="left" valign="top" class="bank_info_table_heading"><strong>Ставка</strong>, %</td>
					</tr><?php
					while ($home_row = mysql_fetch_array($home_res))
					{
						$cc_res = mysql_query("select * from `credit_currency` where `credit_id` = '$home_row[home_id]' and `type` = '3'");
						$cc_count = mysql_num_rows($cc_res);
						?><tr>
							<td align="left" valign="top" class="bank_info_table" rowspan="<?php
							echo $cc_count;
							?>"><a href="<?php echo "/$c_name";?>/credits/home/<?php echo $home_row['home_id'];?>"><?php
								echo $home_row['name'];
							?></a></td><?php
							$i = 0;
							while ($cc_row = mysql_fetch_array($cc_res))
							{
								if ($i > 0)
									echo "<tr>";
								?><td align="left" valign="top" class="bank_table_curency"><?php echo $cc_row['currency']; ?></td>
								<td align="left" valign="top" class="bank_info_table"><?php
									echo "от ".getValue($cc_row['sum_low'])."<br />до ".getValue($cc_row['sum_high']);
								?></td>
								<td align="left" valign="top" class="bank_info_table"><?php
								echo getPeriod($cc_row['period_low'],false)." - ".getPeriod($cc_row['period_high']); ?></td>
								<td align="left" valign="top" class="bank_info_table"><?php
								echo $cc_row['rate_low']."-".$cc_row['rate_high']; ?></td><?php
								$i++;
								if ($i < $cc_count-1)
									echo "</tr>";
							}
						?></tr><?php
					}
				?></table><?php
			}
			else
				echo "<h4 class='gag'>У банка нет ипотечных кредитов</h4>";
			?><div><h3>Кредитные карты</h3></div><?php
			$cart_res = mysql_query("select `cart_id`,`name` from `cart` where `bank_id` = '$bank_row[bank_id]' or (`bank_id` = '$bank_row[parent]' and `regionally` = '1')");
			if (mysql_num_rows($cart_res) > 0)
			{
				?><table width="100%" border="0" cellspacing="0" cellpadding="0">
					<tr>
						<td width="44%" align="left" valign="top" class="bank_info_table_heading"><strong>Название программы</strong></td>
						<td width="15%" align="left" valign="top" class="bank_info_table_heading"><strong>Валюта</strong></td>
						<td width="15%" align="left" valign="top" class="bank_info_table_heading"><strong>Сумма</strong></td>
						<td width="15%" align="left" valign="top" class="bank_info_table_heading"><strong>Срок</strong></td>
						<td width="11%" align="left" valign="top" class="bank_info_table_heading"><strong>Ставка</strong>, %</td>
					</tr><?php
					while ($cart_row = mysql_fetch_array($cart_res))
					{
						$cc_res = mysql_query("select * from `credit_currency` where `credit_id` = '$cart_row[cart_id]' and `type` = '4'");
						$cc_count = mysql_num_rows($cc_res);
						?><tr>
							<td align="left" valign="top" class="bank_info_table" rowspan="<?php
							echo $cc_count;
							?>"><a href="<?php echo "/$c_name";?>/credits/cart/<?php echo $cart_row['cart_id'];?>"><?php
								echo $cart_row['name'];
							?></a></td><?php
							$i = 0;
							while ($cc_row = mysql_fetch_array($cc_res))
							{
								if ($i > 0)
									echo "<tr>";
								?><td align="left" valign="top" class="bank_table_curency"><?php echo $cc_row['currency']; ?></td>
								<td align="left" valign="top" class="bank_info_table"><?php
									echo "от ".getValue($cc_row['sum_low'])."<br />до ".getValue($cc_row['sum_high']);
								?></td>
								<td align="left" valign="top" class="bank_info_table"><?php
								echo getPeriod($cc_row['period_low'],false)." - ".getPeriod($cc_row['period_high']); ?></td>
								<td align="left" valign="top" class="bank_info_table"><?php
								echo $cc_row['rate_low']."-".$cc_row['rate_high']; ?></td><?php
								$i++;
								if ($i < $cc_count-1)
									echo "</tr>";
							}
						?></tr><?php
					}
				?></table><?php
			}
			else
				echo "<h4 class='gag'>У банка нет кредитных карт</h4>";
			?><div><h3>Бизнесу</h3></div><?php
			$business_res = mysql_query("select `business_id`,`name` from `business` where `bank_id` = '$bank_row[bank_id]' or (`bank_id` = '$bank_row[parent]' and `regionally` = '1')");
			if (mysql_num_rows($business_res) > 0)
			{
				?><table width="100%" border="0" cellspacing="0" cellpadding="0">
					<tr>
						<td width="44%" align="left" valign="top" class="bank_info_table_heading"><strong>Название программы</strong></td>
						<td width="15%" align="left" valign="top" class="bank_info_table_heading"><strong>Валюта</strong></td>
						<td width="15%" align="left" valign="top" class="bank_info_table_heading"><strong>Сумма</strong></td>
						<td width="15%" align="left" valign="top" class="bank_info_table_heading"><strong>Срок</strong></td>
						<td width="11%" align="left" valign="top" class="bank_info_table_heading"><strong>Ставка</strong>, %</td>
					</tr><?php
					while ($business_row = mysql_fetch_array($business_res))
					{
						$cc_res = mysql_query("select * from `credit_currency` where `credit_id` = '$business_row[business_id]' and `type` = '5'");
						$cc_count = mysql_num_rows($cc_res);
						?><tr>
							<td align="left" valign="top" class="bank_info_table" rowspan="<?php
							echo $cc_count;
							?>"><a href="<?php echo "/$c_name";?>/credits/business/<?php echo $business_row['business_id'];?>"><?php
								echo $business_row['name'];
							?></a></td><?php
							$i = 0;
							while ($cc_row = mysql_fetch_array($cc_res))
							{
								if ($i > 0)
									echo "<tr>";
								?><td align="left" valign="top" class="bank_table_curency"><?php echo $cc_row['currency']; ?></td>
								<td align="left" valign="top" class="bank_info_table"><?php
									echo "от ".getValue($cc_row['sum_low'])."<br />до ".getValue($cc_row['sum_high']);
								?></td>
								<td align="left" valign="top" class="bank_info_table"><?php
								echo getPeriod($cc_row['period_low'],false)." - ".getPeriod($cc_row['period_high']); ?></td>
								<td align="left" valign="top" class="bank_info_table"><?php
								echo $cc_row['rate_low']."-".$cc_row['rate_high']; ?></td><?php
								$i++;
								if ($i < $cc_count-1)
									echo "</tr>";
							}
						?></tr><?php
					}
				?></table><?php
			}
			else
				echo "<h4 class='gag'>У банка нет бизнес кредитов</h4>";
			?>
		</td>
	</tr>
</table>
<div class="inside_block">
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
		<tr valign='top'>
			<td width="344" class="inside_info"><?php
				require_once APP."bank_list.php";
				require_once APP."currency_rates.php";
			?></td>
			<td width="646"><?php
				echo "<h2>$bank_row[name]</h2>";
				if ($bank_row['info'] != "")
					echo "<p>".getRichText($bank_row['info'])."</p>";
				else
				{
					$info = mysql_fetch_array(mysql_query("select * from `info` where `info_id` = '11' limit 1"));
					$text = getRichText($info['text']);
					$text = preg_replace("/{bank}/",$bank_row['name'],$text);
					echo "<p>$text</p>";
				}
			?></td>
		</tr>
	</table>
</div>

<?php require_once APP.FOOTERFILE; ?>